package com.guigu.controller.lq.controller;

import com.guigu.controller.lq.pojo.LqVip;
import com.guigu.controller.lq.pojo.LqVisit;
import com.guigu.controller.lq.pojo.PageVO;
import com.guigu.controller.lq.service.LqVipSetvice;
import com.guigu.controller.lq.service.LqVisitService;
import com.guigu.pojo.Vip;
import com.guigu.pojo.Visit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@RestController
public class LqSfrjController {
    @Autowired
    LqVisitService lqVisitService;
    @Autowired
    LqVipSetvice lqVipSetvice;
    @RequestMapping("/findsf")
    public PageVO<LqVisit>findsf(@RequestBody PageVO pageVO){
        PageVO<LqVisit> findsf = lqVisitService.findsf(pageVO.getPage(), pageVO.getNum(), pageVO.getVipname());
        return findsf;
    }
    @RequestMapping("/addsf")
    public int addsf(@RequestParam("pictureFile") MultipartFile pictureFile,LqVisit lqVisit) throws IOException {
        // 图片上传
        // 设置图片名称，不能重复，可以使用uuid
        String picName = UUID.randomUUID().toString();

        // 获取文件名
        String oriName = pictureFile.getOriginalFilename();
        // 获取图片后缀
        String extName = oriName.substring(oriName.lastIndexOf("."));


        // 开始上传
        pictureFile.transferTo(new File("D:/image/" + picName + extName));

        lqVisit.setScimg(picName+extName);
        int addsf = lqVisitService.addsf(lqVisit);
        System.out.println(addsf);
        return addsf;
    }
    @RequestMapping("/cxsf")
    public List<Vip>cxsf(@RequestBody Vip Vip){
        List<Vip> cxsf = lqVipSetvice.cxsf(Vip.getVipname());
        return cxsf;
    }
    @RequestMapping("/upsf")
    public int upsf(@RequestParam("pictureFile2") MultipartFile pictureFile,LqVisit lqVisit) throws IOException {
        // 图片上传
        // 设置图片名称，不能重复，可以使用uuid
        String picName = UUID.randomUUID().toString();

        // 获取文件名
        String oriName = pictureFile.getOriginalFilename();
        // 获取图片后缀
        String extName = oriName.substring(oriName.lastIndexOf("."));


        // 开始上传
        pictureFile.transferTo(new File("D:/image/" + picName + extName));

        lqVisit.setScimg(picName+extName);
        int upsf = lqVisitService.upsf(lqVisit);

        return upsf;
    }
    @RequestMapping("/selsf")
    public LqVisit selsf(@RequestBody LqVisit lqVisit){
        LqVisit selsf = lqVisitService.selsf(lqVisit.getId());
        return selsf;
    }
    @RequestMapping("/delsf")
    public  int delsf(@RequestBody LqVisit lqVisit){
        int delsf = lqVisitService.delsf(lqVisit.getId());
        return delsf;
    }
}
